package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.dto.StorelistDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Storelist;
import com.ruoyi.system.service.IStorelistService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 门店信息Controller
 *
 * @author ruoyi
 * @date 2025-04-30
 */
@RestController
@RequestMapping("/system/storelist")
public class StorelistController extends BaseController
{
    @Autowired
    private IStorelistService storelistService;

    /**
     * 查询门店信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Storelist storelist)
    {
        startPage();
        List<StorelistDto> list = storelistService.selectStorelistList(storelist);
        return getDataTable(list);
    }


    /**
     * 查询门店基础信息列表
     */
    @GetMapping("/listBase")
    public TableDataInfo listBase()
    {
        startPage();
        List<Storelist> list = storelistService.selectStoreBaseList();
        return getDataTable(list);
    }


    /**
     * 导出门店信息列表
     */
    @Log(title = "门店信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Storelist storelist)
    {
        List<StorelistDto> list = storelistService.selectStorelistList(storelist);
        ExcelUtil<StorelistDto> util = new ExcelUtil<StorelistDto>(StorelistDto.class);
        util.exportExcel(response, list, "门店信息数据");
    }


    /**
     * 获取门店信息详细信息
     */
    @GetMapping(value = "/{storeId}")
    public AjaxResult getInfo(@PathVariable("storeId") Long storeId)
    {
        return success(storelistService.selectStorelistByStoreId(storeId));
    }

    /**
     * 新增门店信息
     */
    @Log(title = "门店信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Storelist storelist)
    {
        return toAjax(storelistService.insertStorelist(storelist));
    }

    /**
     * 新增门店所属底图信息
     */
    @Log(title = "新增门店所属底图信息", businessType = BusinessType.INSERT)
    @PostMapping("/addStoreProduct/{storeId}/{productId}")
    public AjaxResult addStoreProduct(@PathVariable("storeId") Long storeId, @PathVariable("productId") Long productId)
    {
        return toAjax(storelistService.addStoreProduct(storeId,productId));
    }

    /**
     * 修改门店信息
     */
    @Log(title = "门店信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Storelist storelist)
    {
        return toAjax(storelistService.updateStorelist(storelist));
    }

    /**
     * 删除门店信息
     */
    @Log(title = "门店信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storeIds}")
    public AjaxResult remove(@PathVariable Long[] storeIds)
    {
        return toAjax(storelistService.deleteStorelistByStoreIds(storeIds));
    }
}
